<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
	<jsp:include page="../head.jsp"/>
<meta http-equiv="X-UA-Compatible" content="edge" />
<title>平台订单体现</title>
<style>
		*{
			margin:0;
			padding:0;
		}
		body{
			font-size: 12px;
			font-family: "微软雅黑";
		}
		ul li{
			list-style:none;
		}
		input{
			width:120px;
		}
		.searchBox{
			width:95%;
			height:47px;
		}
		.searchBox li{
			float:left;
			margin-top:5px;
			margin-right:15px;
		}
		.searchBtn{
			width:70px;
			height:24px;
			background:#3989c8;	
			color:white;
			border:1px solid #77b2e0;	
			border-radius: 3px;	
			margin-left:5px;
		}
		.bottomBtn{			
			width:70px;
			height:24px;
			border:1px solid #77b2e0;
			background:#77b2e0;
			color:white;
			border-radius: 3px;
			margin-left:5px;
			margin-top:5px;
		}	
		.tableOntab td{
			height:37px;
			border-right:none;
		}
		.tableOntab .borderNone{
			border-bottom:none;
		}
		.textbox{
            height: 20px;
            margin: 0;
            padding: 0 2px;
            box-sizing: content-box;
            border: 1px solid #95B8E7;
            vertical-align: middle;
			border-radius:3px;
        }
         .blue_btn{
            border: none;
            border-radius: 5px;
            background-color: #3989c8;
            padding: 5px 20px;
            color:#fff;
        }
		.combo{
   		border-radius:3px;
   		}
</style>

<script type="text/javascript">
	$(function(){
		 
		//加载表格信息
		dataGrid = $('#orderTable').datagrid({
			url:'${ctx}/search/getPlatformList?financeStatus=3&temp='+Math.random(),
			striped : true,
			singleSelect : false,
			idField : 'id',
			pageList : [5,10,20],
			//sortName : 'id',
			//sortOrder : 'asc',
			method : 'get',
			toolbar:'#toolbar',
			pagination:true,
			columns:[[
	          {
					width : '80',
					title : 'id',
					field : 'id',
					hidden : true,
					sortable : true
				},{
					field: 'ck',
					checkbox: true
				},{
				width : '200',
				title : '订单号',
				align : 'center',
				field : 'airlineCode',
				sortable : true,
				formatter : function(value,row){
					var pssBusinessman=CommonConverter.toEmptyString(row.pssOrderNumber);
					var _orderNumber=CommonConverter.toEmptyString(row.orderNumber);
					var value='<p>平台：'+_orderNumber+'</p>'+'<p>供应商：'+pssBusinessman+'</p>';
					return value;
				}
	          },{
					width : '100',
					title : '客户',
					align:'center',
					field : 'buyerName'
			},{
				width : '60',
				title : '航班号',
				align : 'center',
				field : 'airlineId',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:60px;"><tr><td>'+((row.list))[0].airlineNumber+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:60px;"><tr><td>'+((row.list))[0].airlineNumber+'</td>'+'</tr><tr>'+'<td class="borderNone">'+((row.list))[1].airlineNumber+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '135',
				title : '出发',
				align : 'center',
				field : 'charterTypeStr',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].deptCity+'('+(row.list)[0].deptCode+')</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].deptCity+'('+(row.list)[0].deptCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].deptCity+'('+(row.list)[1].deptCode+')'+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '130',
				title : '到达',
				align : 'center',
				field : 'scheduleId',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].arrCity+'('+(row.list)[0].arrCode+')</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:100px;"><tr><td>'+(row.list)[0].arrCity+'('+(row.list)[0].arrCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].arrCity+'('+(row.list)[1].arrCode+')'+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '80',
				title : '出发日期',
				align : 'center',
				field : 'scheduleIdStr',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:80px;"><tr><td>'+(row.list)[0].deptDate+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:80px;"><tr><td>'+(row.list)[0].deptDate+'</td>'+'</tr><tr>'+'<td class="borderNone">'+(row.list)[1].deptDate+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '55',
				title : '出发时刻',
				align:'center',
				field : 'journeyType',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						if(row.list.length == 1){
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].deptTime)+'</td></tr></table>';
						}else if(row.list.length == 2){
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].deptTime)+'</td>'+'</tr><tr>'+'<td class="borderNone">'+CommonConverter.formatFlightTime((row.list)[1].deptTime)+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '55',
				title : '到达时刻',
				align:'center',
				field : 'toDate',
				formatter : function(value,row){
					var table;
					if(row.list != null && row.list.length > 0){
						
						if(row.list.length == 1){
							var backIntervalDay=(row.list)[0].intervalDay;
							var _backIntervalDay="";
							if (backIntervalDay >= 1){
								_backIntervalDay="+"+backIntervalDay;
							}; 
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].arrTime)+_backIntervalDay+'</td></tr></table>';
						}else if(row.list.length == 2){
							var toIntervalDay=(row.list)[0].intervalDay;
							var backIntervalDay=(row.list)[1].intervalDay;
							var _toIntervalDay="";
							var _backIntervalDay="";
							if (toIntervalDay >= 1){
								_toIntervalDay="+"+toIntervalDay;
							}; 
							if (backIntervalDay >= 1){
								_backIntervalDay="+"+backIntervalDay;
							}; 
							table='<table class="tableOntab" style="width:50px;"><tr><td>'+CommonConverter.formatFlightTime((row.list)[0].arrTime)+_toIntervalDay+
							'</td>'+'</tr><tr>'+'<td class="borderNone">'+CommonConverter.formatFlightTime((row.list)[1].arrTime)+_backIntervalDay+'</td></tr></table>';
						}
					}
					return table;
				}
			},{
				width : '50',
				title : '数量',
				align:'center',
				field : 'purchQuantity', 
			},{
				width : '70',
				title : '提现金额',
				align:'center',
				field : 'sum',
			},{
				width : '120',
				title : '财务状态',
				align:'center',
				field : 'financeStatus',
				formatter : function(value,row){
					var orderStatus=CommonConverter.toOrderBizStatusStr(row.orderStatus);
					var financeStatus=CommonConverter.toOrderPayStatusStr(row.financeStatus);
					var value= financeStatus;
					return value;
				}
			},{
				width : '180',
				title : '操作',
				align:'center',
				field : 'fareSaleStr',
				formatter:function(value,row){
					var str = '<span class="bottomBtn" onclick=detail("'+row.orderNumber+'")>查看详情</span>';
					return str;
				}
			}
			] ]
		});
		//点击查询 重新加载列表
		$("#query").click(function(){
			//获取参数
			var orderNumber=$("#_orderNumber").val();
			var toStartAirportCode=$("#_startCity").val();
			var toEndAirportCode=$("#_endCity").val();
			var toStartDate=$("#_startTime").datebox('getValue');
			var toEndDate=$("#_endTime").datebox('getValue');
			if(typeof(toStartAirportCode) == 'undefined'){
				toStartAirportCode = "";
			}
			if(typeof(toEndAirportCode) == 'undefined'){
				toEndAirportCode = "";
			}
			$('#orderTable').datagrid('load',{"orderNumber":orderNumber,"toStartAirportCode":toStartAirportCode,"toEndAirportCode":toEndAirportCode,"toStartDate":toStartDate,"toEndDate":toEndDate,"temp":Math.random()});
		});
		
	});
	//查看详情
	function detail(orderNumber){
		layer.open({
			type: 2,
			title: ['订单详情','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.5,
			area: ['1200px', '500px'],
			content: ['${ctx}/nporder/detail/'+orderNumber, 'yes'],
			success: function(layero, index){
			  layer.full(index);
			},
			end:function(){
			}
		});
	} 
	
	function reqSettlement(){
		var selRows = $('#orderTable').datagrid('getChecked');  
		if(selRows.length == 0){
			layer.alert("请先选择要提现的订单！");
			return false;
		}
		var orderNos = new Array();
		var money = new Number;
		for(var i = 0 ; i < selRows.length ; i++){
			var row = selRows[i];
			money += row.sum;
			orderNos.push(row.orderNumber);
		}
		layer.confirm('您已选择'+selRows.length+'个订单，总金额'+money+'元<br>确认申请提现吗？', {
			  btn: ['确定','取消'] //按钮
			}, function(){
				layer.load(0, {shade: false});
				$.ajax({
					type:'post',
					url:'${ctx}/withdrawal',
					contentType:'application/json;charset=utf-8',
					data:JSON.stringify(orderNos),
					dataType:'json',
					success:function(data){
						layer.closeAll('loading');
						layer.alert('提现申请已提交<br>提现单号：'+data,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
							$('#orderTable').datagrid('reload');
							$("#orderTable").datagrid('clearSelections').datagrid('clearChecked');
							layer.close(index);
						});
					},
					error:function(msg){
						layer.alert("请检查您的网络连接，然后重试！");
						layer.closeAll('loading');
					}
				}); 
			}, function(){
				$("#orderTable").datagrid('clearSelections').datagrid('clearChecked');
				layer.closeAll('loading');
			});
	}
</script>
</head>
<body>

		<div id="toolbar" style="display: none; class="bigBox">
			<input type="button" onclick="reqSettlement()" class="searchBtn" value="申请提现">
		</div>
			<ul class="searchBox">
				<li>订单号：<input  id="_orderNumber" name="charterType" class="easyui-textbox textbox" style="width: 120px;height:20px"/></li>
				<li>出发城市：
				<input type="text" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="_startCity" mod_notice_tip="中文/拼音" />
					<input id="_startCity" name="_startCity" type="hidden" value="" />
				</li>
				<li>到达城市：
				<input type="text" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="_endCity" mod_notice_tip="中文/拼音" />
					<input id="_endCity" name="_endCity" type="hidden" value="" />
				</li>
				<li>
					出发时间 ：<input class="easyui-datebox" id="_startTime" style="width: 120px" />
					至<input class="easyui-datebox" id="_endTime" style="width: 120px" /></li>
				<li><button class='blue_btn' id="query">查询</button></li>
			</ul>
    		<table id="orderTable" class="easyui-datagrid"></table>
<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<jsp:include page="../footer.jsp"/>
</body>
</html>